package com.ohuang.demo

import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.util.Log
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.MutableLiveData

class TwoActivity : AppCompatActivity() {
    private val TAG = "TwoActivity"

    var handler = object : Handler() {
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            Log.d(TAG, "handleMessage: isFinish=" + isFinishing + " isDestroyed=" + isDestroyed)
            btn.postDelayed({
                Log.d(TAG, "post view ")
            }, 2000)
        }
    }
    val btn: View by lazy {
        findViewById<View>(R.id.btn_123)
    }

    val liveData = MutableLiveData<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_two)
        enableEdgeToEdge()
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        liveData.observe(this, {
            Log.d(TAG, "livedata=$it")
        })

        btn.setOnClickListener {
            handler.sendEmptyMessageDelayed(0, 0)
            finish()
        }
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        Log.d(TAG, "onSaveInstanceState: ")

    }

    override fun onDestroy() {
        super.onDestroy()
    }
}